#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int l[105], r[105],Min,Max;
int main()
{
	int t;
	scanf("%d",& t);
	while (t--)
	{
		int n, m, x, y;
		scanf("%d%d%d%d", &n, &m, &x, &y);
		int sum = 0;
		for (int i = 0; i < x; i++)
		{
			scanf("%d%d", &l[i], &r[i]);
		}
		for (int i = 0; i < y; i++)
		{
			int lb, rb;
			scanf("%d%d", &lb, &rb);
			for (int j = 0; j < x; j++)
			{
				Min = min(r[j], rb);
				Max = max(l[j], lb);
				if (Min - Max -m+2>=0)
				{
					sum += Min - Max -m+ 2;
				}
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}